package com.tongtech.space.common.utils;

import com.tongtech.space.common.pojo.UserInfo;

import org.springframework.stereotype.Component;

/**
 * 用户信息Holder
 *
 * @author jinjiayu
 * @since 2021/1/14
 */
@Component
public class UserHolder {
    private static ThreadLocal<UserInfo> userThreadLocal = new ThreadLocal<>();
    private static ThreadLocal<String> authError = new ThreadLocal<>();

    public static UserInfo getCurrentUser() {
        return userThreadLocal.get();
    }

    public static void setCurrentUser(UserInfo userInfo) {
        userThreadLocal.set(userInfo);
    }

    public void clean() {
        userThreadLocal.remove();
        authError.remove();
    }

}
